﻿<Window x:Class="Bend.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        
        xmlns:local="clr-namespace:Bend"        
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"         
        xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"        
        x:Name="ThisWindow"
        mc:Ignorable="d"
        Title="Bend"
        MinWidth="600" 
        MinHeight="100"
        Width="800"
        Height="600"
        SourceInitialized="Window_SourceInitialized" 
        Icon="/Bend;component/Images/Arrow-icon.png" 
        WindowStyle="SingleBorderWindow" ResizeMode="CanResizeWithGrip" Drop="Window_Drop" Closing="Window_Closing" StateChanged="Window_StateChanged" SizeToContent="Manual" AllowDrop="True" AllowsTransparency="False">
    <Window.CommandBindings>
        <CommandBinding Command="Save" Executed="CommandSave"/>
        <CommandBinding Command="Open" Executed="CommandOpen"/>
        <CommandBinding Command="New" Executed="CommandNew"/>
        <CommandBinding Command="Refresh" Executed="CommandRefresh"/>
        <CommandBinding Command="Find" Executed="CommandFind"/>
        <CommandBinding Command="Replace" Executed="CommandReplace"/>
        <CommandBinding Command="GoToPage" Executed="CommandGoto"/>
        <CommandBinding Command="Help" Executed="CommandHelp"/>
    </Window.CommandBindings>
    <Window.InputBindings>
        <KeyBinding Key="S" Modifiers="Control" Command="Save"></KeyBinding>
        <KeyBinding Key="O" Modifiers="Control" Command="Open"></KeyBinding>
        <KeyBinding Key="N" Modifiers="Control" Command="New"></KeyBinding>
        <KeyBinding Key="F" Modifiers="Control" Command="Find"></KeyBinding>
        <KeyBinding Key="H" Modifiers="Control" Command="Replace"></KeyBinding>
        <KeyBinding Key="G" Modifiers="Control" Command="GoToPage"></KeyBinding>
        <KeyBinding Key="F5" Command="Refresh"></KeyBinding>
    </Window.InputBindings>
    <Window.Resources>
        <Style x:Key="PlainStyle" TargetType="{x:Type local:MainWindow}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:MainWindow}">
                        <ContentPresenter Content="{TemplateBinding Content}"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- ContextMenu for Tabs-->
        <ContextMenu x:Key="TabTitleContextMenu" x:Shared="true" MinWidth="150">
            <MenuItem Header="Refresh" Click="ContextRefresh" MinHeight="20" InputGestureText="F5">
                <MenuItem.Icon>
                    <TextBlock FontFamily="Segoe UI Symbol" FontSize="10"></TextBlock>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Close" Click="ContextClose" MinHeight="20">
                <MenuItem.Icon>
                    <Image Source="/Bend;component/Images/Close.png" Width="12" Height="12" Margin="-3,0,0,0"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Close other tabs" Click="ContextCloseOtherTabs" MinHeight="20"/>
            <Separator/>
            <MenuItem Header="File encoding" Click="ContextFileEncoding"  MinHeight="20">
                <MenuItem.Icon>
                    <Image Source="/Bend;component/Images/HDD.png" Width="12" Height="12" Margin="-3,0,0,0"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Copy full path" Click="ContextCopyFullPath" MinHeight="20"/>
            <MenuItem Header="Open containing folder" Click="ContextOpenContainingFolder" MinHeight="20">
                <MenuItem.Icon>
                    <TextBlock FontFamily="Segoe UI Symbol"></TextBlock>
                </MenuItem.Icon>
            </MenuItem>
            <Separator/>
            <MenuItem Header="Reopen last session" Click="ReopenLastSession" MinHeight="20"/>
        </ContextMenu>

        <!-- ContextMenu for Editor -->
        <ContextMenu x:Key="EditorContextMenu" x:Shared="true" MinWidth="150">
            <MenuItem Header="Cut" Click="ContextCut" MinHeight="20" InputGestureText="Ctrl + X">
                <MenuItem.Icon>
                    <TextBlock FontFamily="Segoe UI Symbol" ></TextBlock>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Copy" Click="ContextCopy" MinHeight="20" InputGestureText="Ctrl + C">
                <MenuItem.Icon>
                    <TextBlock FontFamily="Segoe UI Symbol"></TextBlock>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Paste" Click="ContextPaste" MinHeight="20" InputGestureText="Ctrl + V">
                <MenuItem.Icon>
                    <TextBlock FontFamily="Segoe UI Symbol"></TextBlock>
                </MenuItem.Icon>
            </MenuItem>
            <Separator></Separator>
            <MenuItem Header="Undo" Click="ContextUndo" MinHeight="20" InputGestureText="Ctrl + Z">
                <MenuItem.Icon>
                    <TextBlock FontFamily="Segoe UI Symbol"></TextBlock>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Redo" Click="ContextRedo" MinHeight="20" InputGestureText="Ctrl + Y">
                <MenuItem.Icon>
                    <TextBlock FontFamily="Segoe UI Symbol"></TextBlock>
                </MenuItem.Icon>
            </MenuItem>
            <Separator></Separator>
            <MenuItem x:Name="GoToLine" Click="ContextGoToLine" Header="Goto" MinHeight="20" InputGestureText="Ctrl + G">
            </MenuItem>
            <MenuItem x:Name="Record" Click="ContextRecord" Header="Record" MinHeight="20">
                <MenuItem.Icon>
                    <TextBlock FontFamily="Segoe UI Symbol"></TextBlock>
                </MenuItem.Icon>                
            </MenuItem>
        </ContextMenu>

        <!-- Define animation for moving to settings window-->
        <Storyboard x:Key="slideSettingsIn" AutoReverse="False">
            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Settings" Storyboard.TargetProperty="(UIElement.Visibility)">
                <DiscreteObjectKeyFrame KeyTime="0:00:00" Value="{x:Static Visibility.Visible}"/>
            </ObjectAnimationUsingKeyFrames>
            <DoubleAnimation                            
                            Storyboard.TargetName="MainWindowGridRotateTransform"
                            Storyboard.TargetProperty="Angle"                            
                            From="0"
                            To="180"
                            Duration="0:0:1"
                            DecelerationRatio="0.6"
             />
            <DoubleAnimation                            
                            Storyboard.TargetName="SettingsGridRotateTransform"
                            Storyboard.TargetProperty="Angle"                            
                            From="-180"
                            To="0"
                            Duration="0:0:1"
                            DecelerationRatio="0.6"
             />
        </Storyboard>
        <Storyboard x:Key="slideSettingsOut" AutoReverse="False">
            <DoubleAnimation                            
                            Storyboard.TargetName="MainWindowGridRotateTransform"
                            Storyboard.TargetProperty="Angle"                            
                            From="180"
                            To="0"
                            Duration="0:0:1"
                            DecelerationRatio="0.6"
             />
            <DoubleAnimation                            
                            Storyboard.TargetName="SettingsGridRotateTransform"
                            Storyboard.TargetProperty="Angle"                            
                            From="0"
                            To="-180"
                            Duration="0:0:1"
                            DecelerationRatio="0.6"
             />
            <ObjectAnimationUsingKeyFrames BeginTime="00:00:1.1" Storyboard.TargetName="Settings" Storyboard.TargetProperty="(UIElement.Visibility)">
                <DiscreteObjectKeyFrame KeyTime="0:00:00" Value="{x:Static Visibility.Hidden}"/>
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="fileSave" AutoReverse="true">
            <DoubleAnimation                            
                            Storyboard.TargetName="Editor"
                            Storyboard.TargetProperty="(UIElement.Opacity)"
                            From="1"
                            To="0.2"
                            Duration="0:0:1"
                            DecelerationRatio="0.6"
             />
        </Storyboard>
    </Window.Resources>
    <Grid Name="ClientAreaGrid" Background="{DynamicResource BackgroundBrush}">
        <Grid Name="MainWindowGrid">
            <Grid.RenderTransform>
                <RotateTransform x:Name="MainWindowGridRotateTransform"></RotateTransform>
            </Grid.RenderTransform>
            <Grid Name="Editor" Margin="0,73,0,0" VerticalAlignment="Stretch" ContextMenu="{StaticResource EditorContextMenu}">
                <Grid.Background>
                    <ImageBrush x:Name="BaseBackgroundImage" ImageSource="Images/SettingsPattern.png" Stretch="Fill" TileMode="Tile" Viewport="0,0,142,142" ViewportUnits="Absolute" />
                </Grid.Background>
            </Grid>
            <Grid Height="40" Name="WindowDrag" VerticalAlignment="Top">
                <WrapPanel MaxHeight="34" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="75,20,0,0" Name="TabBar">
                </WrapPanel>                
            </Grid>
            <Grid Name="MenuBand" Margin="0,38,0,0" Height="36" VerticalAlignment="Top" Background="{DynamicResource BackgroundBrush}">
                <TextBlock HorizontalAlignment="Right" Margin="0,10,20,0" FontFamily="Segoe UI Symbol" Foreground="{DynamicResource ForegroundBrush}" Padding="0">&#xE1A3;</TextBlock>
                <WrapPanel MaxHeight="36" VerticalAlignment="Top" HorizontalAlignment="Right" MinWidth="250">
                    <Separator Width="10" Visibility="Hidden"></Separator>
                    <TextBox Margin="0,5,15,0" FontFamily="Segoe UI" Width="250" FontSize="14" Name="FindText" KeyDown="FindText_KeyDown" VerticalContentAlignment="Center" Text="" MaxLines="1" Padding="2" BorderBrush="Gray" BorderThickness="1.1" TextChanged="FindText_TextChanged" Foreground="{DynamicResource ForegroundBrush}" Background="Transparent" ContextMenu="{x:Null}">
                    </TextBox>
                </WrapPanel>
                <WrapPanel MaxHeight="36" VerticalAlignment="Top" HorizontalAlignment="Left" Background="{DynamicResource BackgroundBrush}" >
                    <Label VerticalAlignment="top" VerticalContentAlignment="Center" Height="36" FontStretch="Normal" Foreground="{DynamicResource ForegroundBrush}" FontWeight="ExtraLight" FontFamily="Segoe UI" FontSize="18" Padding="10,0" IsTabStop="True" PreviewMouseLeftButtonUp="NewButtonUp">New</Label>
                    <Label VerticalAlignment="top" VerticalContentAlignment="Center" Height="36" FontStretch="Normal" Foreground="{DynamicResource ForegroundBrush}" FontWeight="ExtraLight" FontFamily="Segoe UI" FontSize="18" Padding="10,0" IsTabStop="True" PreviewMouseLeftButtonUp="OpenButtonUp" >Open</Label>
                    <Label VerticalAlignment="top" VerticalContentAlignment="Center" Height="36" FontStretch="Normal" Foreground="{DynamicResource ForegroundBrush}" FontWeight="ExtraLight" FontFamily="Segoe UI" FontSize="18" Padding="10,0" IsTabStop="True" PreviewMouseLeftButtonUp="SaveButtonUp" Name="SaveButton">Save</Label>
                    <Label VerticalAlignment="top" VerticalContentAlignment="Center" Height="36" FontStretch="Normal" Foreground="{DynamicResource ForegroundBrush}" FontWeight="ExtraLight" FontFamily="Segoe UI" FontSize="18" Padding="10,0" IsTabStop="True" PreviewMouseLeftButtonUp="SavePlusButtonUp">Save+</Label>
                    <Label VerticalAlignment="top" VerticalContentAlignment="Center" Height="36" FontStretch="Normal" Foreground="{DynamicResource ForegroundBrush}" FontWeight="ExtraLight" FontFamily="Segoe UI" FontSize="18" Padding="15,0" IsTabStop="True" PreviewMouseLeftButtonUp="ReplaceButtonUp">Replace</Label>
                </WrapPanel>
            </Grid>
            <Grid Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="20" />
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="20" />
                </Grid.ColumnDefinitions>
                <WrapPanel Name="StatusBar" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Stretch" Background="{DynamicResource BackgroundBrush}" Margin="49,0,0,0">
                    <WrapPanel>
                        <Label Background="{DynamicResource BackgroundBrush}" FontFamily="Segoe UI" FontSize="9" FontWeight="Bold" Foreground="Gray" HorizontalContentAlignment="Center">LN</Label>
                        <Label Name="Line" Background="{DynamicResource BackgroundBrush}" FontFamily="Segoe UI" FontSize="9" FontWeight="Bold" Foreground="Gray" HorizontalContentAlignment="Center" Margin="5,0,0,0" MinWidth="30"></Label>
                    </WrapPanel>
                    <WrapPanel>
                        <Label Background="{DynamicResource BackgroundBrush}" FontFamily="Segoe UI" FontSize="9" FontWeight="Bold" Foreground="Gray" HorizontalContentAlignment="Center" Margin="10,0,0,0">COL</Label>
                        <Label Name="Column" Background="{DynamicResource BackgroundBrush}" FontFamily="Segoe UI" FontSize="9" FontWeight="Bold" Foreground="Gray" HorizontalContentAlignment="Center" Margin="5,0,0,0" MinWidth="30"></Label>
                    </WrapPanel>
                </WrapPanel>
                <Label Name="StatusText" Visibility="Hidden" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="49,0,0,0" Background="{DynamicResource BackgroundBrush}" FontFamily="Segoe UI" FontSize="9" FontWeight="Bold" Foreground="#19A2DE" HorizontalContentAlignment="Center">
                </Label>
            </Grid>
            <Label Content="Bend" Name="Logo" Width="60" Margin="10,0,0,0" HorizontalAlignment="Left" Foreground="{DynamicResource LogoForegroundBrush}" Height="40" VerticalAlignment="Top" FontWeight="SemiBold" HorizontalContentAlignment="Center" FontFamily="Segoe UI" FontSize="16" Padding="0,8" IsTabStop="True" MouseDown="Logo_MouseDown" Background="{DynamicResource LogoBackgroundBrush}"></Label>
        </Grid>
        <Grid Name="Settings" Visibility="Hidden">
            <Grid.RenderTransform>
                <RotateTransform x:Name="SettingsGridRotateTransform" Angle="-180"></RotateTransform>
            </Grid.RenderTransform>
            <local:Settings x:Name="SettingsControl"/>
            <Label Name="BackButton" Width="50" Margin="0,0,250,0" Padding="0,8" HorizontalAlignment="Right" VerticalAlignment="Top" MouseDown="BackImage_MouseDown" FontWeight="Bold" FontSize="10" Foreground="#19A2DE">BACK</Label>
        </Grid>
        <WrapPanel HorizontalAlignment="Right" Name="WindowControls" VerticalAlignment="Top" Margin="0,8,18,0">
            <TextBlock Name="FullscreenButton"  Width="20" Height="20" PreviewMouseLeftButtonUp="FullscreenButtonUp" TextAlignment="Center" FontWeight="Bold" Foreground="Gray" FontSize="14" >F</TextBlock>
            <Image Name="MinButton" Width="20" Height="20" PreviewMouseLeftButtonUp="MinimizeButtonUp" Source="/Bend;component/Images/min.png" />
            <Image Name="MaxButton" Width="20" Height="20" PreviewMouseLeftButtonUp="MaximizeButtonUp" Source="/Bend;component/Images/max.png" />
            <Image Name="QuitButton" Width="20" Height="20" PreviewMouseLeftButtonUp="QuitButtonUp" Source="/Bend;component/Images/quit.png" />
        </WrapPanel>
        <Canvas Width="20" Height="20" HorizontalAlignment="Right" VerticalAlignment="Bottom" Cursor="SizeNWSE" Name="ResizeCrimp" MouseLeftButtonDown="ResizeCrimp_MouseLeftButtonDown">
            <Canvas.Background>
                <ImageBrush ImageSource="/Bend;component/Images/Crimp.png" />
            </Canvas.Background>
        </Canvas>
    </Grid>
</Window>
